﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ProjectCore.Application;
using ProjectCore.Domain.Model.Entity;
using ProjectCore.Common;
using log4net;
using Microsoft.Extensions.Logging;

namespace ProjectCore.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AdminController : ControllerBase
    {
        private readonly IAppAdmin appAdmin;
        public AdminController(IAppAdmin _appAdmin, ILoggerFactory factory)
        {
            appAdmin = _appAdmin;
        }


        /// <summary>
        /// 管理员显示
        /// </summary>
        /// <returns></returns>
        
        [HttpGet]
        public async Task<ActionResult> GetAdmins(string na = "", int pageIndex = 1, int pageSize = 5)
        {
            Task<HeaderResult<List<Admin>>> admins = appAdmin.GetAdmins(na, pageIndex, pageSize);
            return Ok(await admins);
        }


        /// <summary>
        /// 管理员添加
        /// </summary>
        /// <param name="admin"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> AddAdmin(Admin admin)
        {
            Task<int> n = appAdmin.AddAdmin(admin);

            return Ok(await n);
        }
    }
}
